import complex_query from '@feidao/web/atom/nodejs/db/complex-query';

import { spaceid, systemid } from './atom/config';

interface Message {
	filter: {
		factory_no: RegExp
	};
	page_size: number;
	page_no: number;
	asc: string;
	desc: string;
}

/**
 * @description 正则模糊查询
 * @param
 */

export default async function atom(msg: Message, action_id: string, session_id: string) {
	const cquery = complex_query(action_id, spaceid, systemid);
	//添加查询字段
	cquery.add_field('factory', 'factory_name', 'factory_name')
		.add_field('factory', 'postcode', 'postcode')
		.add_field('factory', 'factory_no', 'factory_no')
		.where_reg('factory', 'factory_no', msg.filter.factory_no)
		.page(msg.page_size, msg.page_no)
		.orderby(msg.asc)
		.orderby_desc(msg.desc);

	const res = await cquery.exec();
	return res;
}
